using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using TestAssemblyInterfaces;
using ILog = log4net.ILog;

namespace LoggingMagic.Tests.Integration.StaticFieldTests
{
    [TestFixture]
    public class TestAssemblyTests
    {
        private ITestClass _target;
        private ILog _logger;

        private Initializer _initializer;
        [TestFixtureSetUp]
        public void FixtureSetUp()
        {
            _initializer = new Initializer();
        }
        [TestFixtureTearDown]
        public void Dispose()
        {
            _initializer.Dispose();
        }

        [SetUp]
        public void Setup()
        {
            _logger = MockRepository.GenerateStrictMock<ILog>();
            Initializer.SetLogger(_logger);

            _logger.Expect(x => x.Info("TestClass..ctor - Entering"));

            _target = Initializer.GetTestAssemblyInstance();
        }

        [Test]
        public void MethodWithoutParameters_Logged()
        {
            _logger.Expect(x => x.Info("TestClass.TestMethod - Entering"));
            _target.TestMethod();

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void MethodWithParameters_Logged()
        {
            _logger.Expect(x => x.Info("TestClass.TestMethodWithParam - Entering"));
            _target.TestMethodWithParam("asd");

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void NotLoggedMethodWithParameters_NotLogged()
        {
            _target.NotLoggedMethodWithParam("asd");

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void PrivateMethod_Logged()
        {
            _logger.Expect(x => x.Info("TestClass.PrivateMethod - Entering"));
            _target.PrivateMethodCaller("asd");

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void MethodWithVars_Logged()
        {
            _logger.Expect(x => x.Info("TestClass.MethodWithPrivateVars - Entering"));
            _target.MethodWithPrivateVars("asd");

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void TestWithReturnValue_Logged()
        {
            _logger.Expect(x => x.Info("TestClass.TestWithReturnValue - Entering"));
            _target.TestWithReturnValue("123");

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void TestMethodWithValueParam_Logged()
        {
            _logger.Expect(x => x.Info("TestClass.TestMethodWithValueParam - Entering"));
            _target.TestMethodWithValueParam(123);

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void TestLoggingWithParameters_Logged()
        {
            _logger.Expect(x => x.InfoFormat("TestClass.TestLoggingWithParameters - Entering('{0}', '{1}')", new object[] { 123, "zxc" }));
            _target.TestLoggingWithParameters(123, "zxc");

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void TestLoggingWithParameters_NullParameter_Logged()
        {
            _logger.Expect(x => x.InfoFormat("TestClass.TestLoggingWithParameters - Entering('{0}', '{1}')", new object[] { 123, null }));
            _target.TestLoggingWithParameters(123, null);

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void TestLoggingWithParameters_MethodWithoutParameters_BracketsExist()
        {
            _logger.Expect(x => x.InfoFormat("TestClass.TestSubWithoutParamsLogTrue - Entering()", new object[] { }));
            _target.TestSubWithoutParamsLogTrue();

            _logger.VerifyAllExpectations();
        }

    }
}